package cn.edu.ptu.jobfairs.web;

import cn.edu.ptu.jobfairs.basic.bo.Member;
import cn.edu.ptu.jobfairs.basic.common.DataResult;
import cn.edu.ptu.jobfairs.basic.common.Result;
import cn.edu.ptu.jobfairs.basic.dto.UserAuthDTO;
import cn.edu.ptu.jobfairs.basic.dto.request.IdDTO;
import cn.edu.ptu.jobfairs.basic.dto.request.PwChangeDTO;
import cn.edu.ptu.jobfairs.basic.dto.response.UserDTO;
import cn.edu.ptu.jobfairs.core.utils.UserUtils;
import cn.edu.ptu.jobfairs.services.UserService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author wutingting.226@163.com
 * @date 2020/8/24
 */
@RestController
@RequestMapping("/u")
public class UserController {
    @Resource
    private UserService userService;

    @PostMapping("/info")
    public Result info() {
        return DataResult.ok(new UserDTO(UserUtils.getUser()));
    }

    @PostMapping("/list")
    public Result list() {
        return userService.listUsers();
    }

    @PostMapping("/add")
    public Result add(Member member) {
        return userService.addUsers(member);
    }

    @PostMapping("/edit")
    public Result edit(Member member) {
        return userService.editUsers(member);
    }

    @PostMapping("/rpw")
    public Result resetPassword(IdDTO idDTO) {
        return userService.resetPassword(idDTO);
    }

    @PostMapping("/cpw")
    public Result changePassword(PwChangeDTO pwChangeDTO) {
        return userService.changePassword(pwChangeDTO);
    }

    @PostMapping("/ga")
    public Result getAuth(IdDTO idDTO) {
        return userService.getAuth(idDTO);
    }

    @PostMapping("/sa")
    public Result setAuth(UserAuthDTO userAuthDTO) {
        return userService.authUser(userAuthDTO);
    }

    @PostMapping("/map")
    public Result getBaseInfo() {
        return userService.listBaseInfo();
    }

}
